package com.flux.utils

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.JsonParser

import java.lang.reflect.Type
import java.util.Date

/**
 * Created by MartinDKent on 2016/1/16.
 */
object GsonUtil {
    private var gson: Gson? = null

    val httpGson: Gson get() = GsonBuilder().serializeNulls().create()

    init {
        gson = Gson()
    }

    fun <T> fromJson(json: String, cls: Class<T>): T {
        return gson!!.fromJson(json, cls)
    }

    fun <T> fromJson(json: String, typeOfT: Type): T {
        return gson!!.fromJson(json, typeOfT)
    }

    fun toJson(src: Any): String {
        return gson!!.toJson(src)
    }

    fun getObject(json: String) = JsonParser().parse(json).asJsonObject
}